package org.example.route.controller.AdminController;



import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.route.model.dto.BaseRequest;
import org.example.route.model.dto.RouteDTO;
import org.example.route.model.dto.RouteQueryDTO;
import org.example.route.model.pojo.Result;
import org.example.route.model.vo.RouteVO;
import org.example.route.service.RouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

//添加新线路
@RestController
@RequestMapping("/admin/route")
@Slf4j
@Tag(name = "线路管理")
public class RouteController {
    @Autowired
    private RouteService routeService;

    //添加线路
    /**完成一测**/
    @Operation(summary = "添加线路")
    @PostMapping("/add")
    public Result add(@RequestBody RouteDTO routeDTO)
    {
       log.info("添加线路,{}",routeDTO);
       routeService.add(routeDTO);
       return Result.success();

    }

    //查询路线
    /**完成一测**/
    @Operation(summary = "查询线路")
    @PostMapping("/list")
    public Result<List<RouteVO>> list(@RequestBody RouteQueryDTO routeQueryDTO)
    {
        log.info("查询线路,{}",routeQueryDTO);
        List<RouteVO> routeVOList = routeService.list(routeQueryDTO);
        return Result.success(routeVOList);
    }

    //删除路线，此法比较复杂

   @PostMapping("/delete")
   @Operation(summary = "删除线路")
    public Result delete(@RequestBody BaseRequest baseRequest)
    {
        log.info("删除线路,{}",baseRequest);
        routeService.delete(baseRequest);
        return Result.success();
    }



    //TODO 修改路线
    @Operation(summary = "修改线路")
    @PostMapping("/update")
    public Result update(@RequestBody RouteDTO routeDTO){
        log.info("修改线路,{}",routeDTO);
        routeService.update(routeDTO);
        return Result.success();
    }



}
